home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-decl2.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  72KB  |  2,314 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include "config.h"
  30. #include "tree.h"
  31. #include "flags.h"
  32. #include "cplus-tree.h"
  33. #include "cplus-parse.h"
  34. #include "cplus-decl.h"
  35. #include "assert.h"
  36.  
  37. #define NULL 0
  38.  
  39. extern tree grokdeclarator ();
  40. static void grok_function_init ();
  41.  
  42. /* A list of virtual function tables we must make sure to write out.  */
  43. tree pending_vtables;
  44.  
  45. /* A list of static class variables.  This is needed, because a
  46.    static class variable can be declared inside the class without
  47.    an initializer, and then initialized, staticly, outside the class.  */
  48. tree pending_statics;
  49.  
  50. extern tree pending_addressable_inlines;
  51.  
  52. /* Used to help generate temporary names which are unique within
  53.    a function.  Reset to 0 by start_function.  */
  54.  
  55. static int temp_name_counter;
  56.  
  57. /* Same, but not reset.  Local temp variables and global temp variables
  58.    can have the same name.  */
  59. static int global_temp_name_counter;
  60.  
  61. /* The (assembler) name of the first globally-visible object output.  */
  62. extern char * first_global_object_name;
  63.  
  64. /* C (and C++) language-specific option variables.  */
  65.  
  66. /* Nonzero means allow type mismatches in conditional expressions;
  67.    just make their values `void'.   */
  68.  
  69. int flag_cond_mismatch;
  70.  
  71. /* Nonzero means don't recognize the keyword `asm'.  */
  72.  
  73. int flag_no_asm;
  74.  
  75. /* Nonzero means do some things the same way PCC does.  */
  76.  
  77. int flag_traditional;
  78.  
  79. /* Nonzero means warn about implicit declarations.  */
  80.  
  81. int warn_implicit = 1;
  82.  
  83. /* Nonzero means warn about function definitions that default the return type
  84.    or that use a null return and have a return-type other than void.  */
  85.  
  86. int warn_return_type;
  87.  
  88. /* Nonzero means give string constants the type `const char *'
  89.    to get extra warnings from them.  These warnings will be too numerous
  90.    to be useful, except in thoroughly ANSIfied programs.  */
  91.  
  92. int warn_write_strings;
  93.  
  94. /* Nonzero means warn about pointer casts that can drop a type qualifier
  95.    from the pointer target type.  */
  96.  
  97. int warn_cast_qual;
  98.  
  99. /* Nonzero means warn about sizeof(function) or addition/subtraction
  100.    of function pointers.  */
  101.  
  102. int warn_pointer_arith;
  103.  
  104. /* Nonzero means warn for all old-style non-prototype function decls.  */
  105.  
  106. int warn_strict_prototypes;
  107.  
  108. /* Non-zero means warn in function declared in derived class has the
  109.    same name as a virtual in the base class, but fails to match the
  110.    type signature of any virtual function in the base class.  */
  111. int warn_overloaded_virtual;
  112.  
  113. /* Non-zero means warn when converting between different enumeral types.  */
  114. int warn_enum_clash;
  115.  
  116. /* Nonzero means `$' can be in an identifier.
  117.    See cccp.c for reasons why this breaks some obscure ANSI C programs.  */
  118.  
  119. #ifndef DOLLARS_IN_IDENTIFIERS
  120. #define DOLLARS_IN_IDENTIFIERS 0
  121. #endif
  122. int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
  123.  
  124. /* Nonzero for -no-strict-prototype switch: do not consider empty
  125.    argument prototype to mean function takes no arguments.  */
  126.  
  127. /* Nonzero causes a call to __main() to be emmitted as first instruction of */
  128. /* main() */
  129.  
  130. int flag__main = 1;
  131.  
  132. int strict_prototype = 1;
  133. int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
  134.  
  135. /* Nonzero means that labels can be used as first-class objects */
  136.  
  137. int flag_labels_ok;
  138.  
  139. /* Non-zero means to collect statistics which might be expensive
  140.    and to print them when we are done.  */
  141. int flag_detailed_statistics;
  142.  
  143. /* C++ specific flags.  */   
  144. /* Nonzero for -fall-virtual: make every member function (except
  145.    constructors) lay down in the virtual function table.  Calls
  146.    can then either go through the virtual function table or not,
  147.    depending.  */
  148.  
  149. int flag_all_virtual;
  150.  
  151. /* Zero means that `this' is a *const.  This gives nice behavior in the
  152.    2.0 world.  1 gives 1.2-compatible behavior.  2 gives Spring behavior.   */
  153.  
  154. int flag_this_is_variable;
  155.  
  156. /* Nonzero means memoize our member lookups.  */
  157.  
  158. int flag_memoize_lookups; int flag_save_memoized_contexts;
  159.  
  160. /* Nonzero means to implement `dynamic' features a la SOS.  */
  161.  
  162. int flag_dynamic;
  163.  
  164. /* 3 means write out only virtuals function tables `defined'
  165.    in this implementation file.
  166.    2 means write out only specific virtual function tables
  167.    and give them (C) public visibility.
  168.    1 means write out virtual function tables and give them
  169.    (C) public visibility.
  170.    0 means write out virtual function tables and give them
  171.    (C) static visibility (default).
  172.    -1 means declare virtual function tables extern.  */
  173.  
  174. int write_virtuals;
  175.  
  176. /* Nonzero means we should attempt to elide constructors when possible.  */
  177.  
  178. int flag_elide_constructors;
  179.  
  180. /* Nonzero means if the type has methods, only output debugging
  181.    information if methods are actually written to the asm file.  */
  182.  
  183. int flag_minimal_debug = 0;
  184.  
  185. /* Same, but for inline functions: nonzero means write out debug info
  186.    for inlines.  Zero means do not.  */
  187.  
  188. int flag_inline_debug;
  189.  
  190. /* Nonzero means recognize and handle exception handling constructs.
  191.    2 means handle exceptions the way Spring wants them handled.  */
  192.  
  193. int flag_handle_exceptions;
  194.  
  195. /* Nonzero means that member functions defined in class scope are
  196.    inline by default.  */
  197.  
  198. int flag_default_inline = 1;
  199.  
  200. /* Nonzero means that functions declared `inline' will be treated
  201.    as `static'.  Used in conjunction with -g.  */
  202. int flag_no_inline = 0;
  203.  
  204. /* Controls whether enums and ints freely convert.
  205.    1 means with complete freedom.
  206.    0 means enums can convert to ints, but not vice-versa.  */
  207. int flag_int_enum_equivalence;
  208.  
  209. /* Table of language-dependent -f options.
  210.    STRING is the option name.  VARIABLE is the address of the variable.
  211.    ON_VALUE is the value to store in VARIABLE
  212.     if `-fSTRING' is seen as an option.
  213.    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
  214.  
  215. static struct { char *string; int *variable; int on_value;} lang_f_options[] =
  216. {
  217.   {"signed-char", &flag_signed_char, 1},
  218.   {"unsigned-char", &flag_signed_char, 0},
  219.   {"short-enums", &flag_short_enums, 1},
  220.   {"cond-mismatch", &flag_cond_mismatch, 1},
  221.   {"asm", &flag_no_asm, 0},
  222.   {"labels-ok", &flag_labels_ok, 1},
  223.   {"stats", &flag_detailed_statistics, 1},
  224.   {"this-is-variable", &flag_this_is_variable, 1},
  225.   {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
  226.   {"warn-implicit", &warn_implicit, 1},
  227.   {"all-virtual", &flag_all_virtual, 1},
  228.   {"memoize-lookups", &flag_memoize_lookups, 1},
  229.   {"elide-constructors", &flag_elide_constructors, 1},
  230.   {"minimal-debug", &flag_minimal_debug, 1},
  231.   {"inline-debug", &flag_inline_debug, 0},
  232.   {"handle-exceptions", &flag_handle_exceptions, 1},
  233.   {"spring-exceptions", &flag_handle_exceptions, 2},
  234.   {"default-inline", &flag_default_inline, 1},
  235.   {"inline", &flag_no_inline, 0},
  236.   {"dollars-in-identifiers", &dollars_in_ident, 1},
  237.   {"enum-int-equiv", &flag_int_enum_equivalence, 1},
  238.   {"__main", &flag__main, 1},
  239. };
  240.  
  241. /* Decode the string P as a language-specific option.
  242.    Return 1 if it is recognized (and handle it);
  243.    return 0 if not recognized.  */
  244.  
  245. int   
  246. lang_decode_option (p)
  247.      char *p;
  248. {
  249.   if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
  250.     flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
  251.     flag_this_is_variable = 1;
  252.   /* The +e options are for cfront compatability.  */
  253.   else if (p[0] == '+' && p[1] == 'e')
  254.     {
  255.       int old_write_virtuals = write_virtuals;
  256.       if (p[2] == '1')
  257.     write_virtuals = 1;
  258.       else if (p[2] == '0')
  259.     write_virtuals = -1;
  260.       else if (p[2] == '2')
  261.     write_virtuals = 2;
  262.       else error ("invalid +e option");
  263.       if (old_write_virtuals != 0
  264.       && write_virtuals != old_write_virtuals)
  265.     error ("conflicting +e options given");
  266.     }
  267.   else if (p[0] == '-' && p[1] == 'f')
  268.     {
  269.       /* Some kind of -f option.
  270.      P's value is the option sans `-f'.
  271.      Search for it in the table of options.  */
  272.       int found = 0, j;
  273.  
  274.       p += 2;
  275.       /* Try special -f options.  */
  276.  
  277.       if (!strcmp (p, "save-memoized"))
  278.     {
  279.       flag_memoize_lookups = 1;
  280.       flag_save_memoized_contexts = 1;
  281.       found = 1;
  282.     }
  283.       else if (!strcmp (p, "SOS"))
  284.     {
  285.       flag_all_virtual = 2;
  286.       found = 1;
  287.     }
  288.       else for (j = 0;
  289.         !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
  290.         j++)
  291.     {
  292.       if (!strcmp (p, lang_f_options[j].string))
  293.         {
  294.           *lang_f_options[j].variable = lang_f_options[j].on_value;
  295.           /* A goto here would be cleaner,
  296.          but breaks the vax pcc.  */
  297.           found = 1;
  298.         }
  299.       if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
  300.           && ! strcmp (p+3, lang_f_options[j].string))
  301.         {
  302.           *lang_f_options[j].variable = ! lang_f_options[j].on_value;
  303.           found = 1;
  304.         }
  305.     }
  306.       return found;
  307.     }
  308.   else if (p[0] == '-' && p[1] == 'W')
  309.     {
  310.       /* The -W options control the warning behavior of the compiler.  */
  311.       p += 2;
  312.  
  313.       if (!strcmp (p, "implicit"))
  314.     warn_implicit = 1;
  315.       else if (!strcmp (p, "return-type"))
  316.     warn_return_type = 1;
  317.       else if (!strcmp (p, "write-strings"))
  318.     warn_write_strings = 1;
  319.       else if (!strcmp (p, "cast-qual"))
  320.     warn_cast_qual = 1;
  321.       else if (!strcmp (p, "pointer-arith"))
  322.     warn_pointer_arith = 1;
  323.       else if (!strcmp (p, "strict-prototypes"))
  324.     warn_strict_prototypes = 1;
  325.       else if (!strcmp (p, "comment"))
  326.     ;            /* cpp handles this one.  */
  327.       else if (!strcmp (p, "comments"))
  328.     ;            /* cpp handles this one.  */
  329.       else if (!strcmp (p, "trigraphs"))
  330.     ;            /* cpp handles this one.  */
  331.       else if (!strcmp (p, "all"))
  332.     {
  333.       extra_warnings = 1;
  334.       warn_implicit = 1;
  335.       warn_return_type = 1;
  336.       warn_unused = 1;
  337.       warn_switch = 1;
  338. #if 0
  339.       warn_enum_clash = 1;
  340. #endif
  341.       warn_inline = 1;
  342.     }
  343.  
  344.       else if (!strcmp (p, "overloaded-virtual"))
  345.     warn_overloaded_virtual = 1;
  346.       else if (!strcmp (p, "enum-clash"))
  347.     warn_enum_clash = 1;
  348.       else return 0;
  349.     }
  350.   else if (!strcmp (p, "-ansi"))
  351.     flag_no_asm = 1, dollars_in_ident = 0;
  352.   else
  353.     return 0;
  354.  
  355.   return 1;
  356. }
  357.  
  358. /* Incorporate `const' and `volatile' qualifiers for member functions.
  359.    FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
  360.    QUALS is a list of qualifiers.  */
  361. tree
  362. grok_method_quals (ctype, function, quals)
  363.      tree ctype, function, quals;
  364. {
  365.   tree fntype = TREE_TYPE (function);
  366.   tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
  367.  
  368.   assert (quals != NULL_TREE);
  369.   do
  370.     {
  371.       extern tree ridpointers[];
  372.  
  373.       if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
  374.     {
  375.       if (TREE_READONLY (ctype))
  376.         error ("duplicate `%s' %s",
  377.            IDENTIFIER_POINTER (TREE_VALUE (quals)),
  378.            (TREE_CODE (function) == FUNCTION_DECL
  379.             ? "for member function" : "in type declaration"));
  380.       ctype = build_type_variant (ctype, 1, TREE_VOLATILE (ctype));
  381.       build_pointer_type (ctype);
  382.     }
  383.       else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
  384.     {
  385.       if (TREE_VOLATILE (ctype))
  386.         error ("duplicate `%s' %s",
  387.            IDENTIFIER_POINTER (TREE_VALUE (quals)),
  388.            (TREE_CODE (function) == FUNCTION_DECL
  389.             ? "for member function" : "in type declaration"));
  390.       ctype = build_type_variant (ctype, TREE_READONLY (ctype), 1);
  391.       build_pointer_type (ctype);
  392.     }
  393.       else
  394.     abort ();
  395.       quals = TREE_CHAIN (quals);
  396.     }
  397.   while (quals);
  398.   fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
  399.                     (TREE_CODE (fntype) == METHOD_TYPE
  400.                      ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
  401.                      : TYPE_ARG_TYPES (fntype)));
  402.   if (raises)
  403.     fntype = build_exception_variant (ctype, fntype, raises);
  404.  
  405.   TREE_TYPE (function) = fntype;
  406.   return ctype;
  407. }
  408.  
  409.  
  410. /* Classes overload their constituent function names automatically.
  411.    When a function name is declared in a record structure,
  412.    its name is changed to it overloaded name.  Since names for
  413.    constructors and destructors can conflict, we place a leading
  414.    '$' for destructors.
  415.  
  416.    CNAME is the name of the class we are grokking for.
  417.  
  418.    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
  419.  
  420.    FLAGS contains bits saying what's special about today's
  421.    arguments.  1 == DESTRUCTOR.  2 == OPERATOR.
  422.  
  423.    If FUNCTION is a destructor, then we must add the `auto-delete' field
  424.    as a second parameter.  There is some hair associated with the fact
  425.    that we must "declare" this variable in the manner consistent with the
  426.    way the rest of the arguements were declared.
  427.  
  428.    If FUNCTION is a constructor, and we are doing SOS hacks for dynamic
  429.    classes, then the second hidden argument is the virtual function table
  430.    pointer with which to initialize the object.
  431.  
  432.    QUALS are the qualifiers for the this pointer.  */
  433.  
  434. void
  435. grokclassfn (ctype, cname, function, flags, complain, quals)
  436.      tree ctype, cname, function;
  437.      enum overload_flags flags;
  438.      tree quals;
  439. {
  440.   tree fn_name = DECL_NAME (function);
  441.   tree arg_types;
  442.   tree parm;
  443.   char *name;
  444.  
  445.   if (fn_name == NULL_TREE)
  446.     {
  447.       error ("name missing for member function");
  448.       fn_name = get_identifier ("<anonymous>");
  449.       DECL_NAME (function) = DECL_ORIGINAL_NAME (function) = fn_name;
  450.     }
  451.  
  452.   if (quals)
  453.     ctype = grok_method_quals (ctype, function, quals);
  454.  
  455.   arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
  456.   if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
  457.     {
  458.       /* Must add the class instance variable up front.  */
  459.       /* Right now we just make this a pointer.  But later
  460.      we may wish to make it special.  */
  461.       tree type = TREE_VALUE (arg_types);
  462.  
  463.       if (flags == DTOR_FLAG)
  464.     type = TYPE_MAIN_VARIANT (type);
  465.       else if (DECL_CONSTRUCTOR_P (function))
  466.     {
  467.       if (TYPE_DYNAMIC (ctype))
  468.         {
  469.           parm = build_decl (PARM_DECL, get_identifier (AUTO_VTABLE_NAME), TYPE_POINTER_TO (ptr_type_node));
  470.           TREE_USED (parm) = 1;
  471.           TREE_READONLY (parm) = 1;
  472.           DECL_ARG_TYPE (parm) = TYPE_POINTER_TO (ptr_type_node);
  473.           TREE_CHAIN (parm) = last_function_parms;
  474.           last_function_parms = parm;
  475.         }
  476.  
  477.       if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
  478.         {
  479.           DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
  480.           /* In this case we need "in-charge" flag saying whether
  481.          this constructor is responsible for initialization
  482.          of virtual baseclasses or not.  */
  483.           parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
  484.           DECL_ARG_TYPE (parm) = integer_type_node;
  485.           TREE_REGDECL (parm) = 1;
  486.           TREE_CHAIN (parm) = last_function_parms;
  487.           last_function_parms = parm;
  488.         }
  489.     }
  490.  
  491.       parm = build_decl (PARM_DECL, this_identifier, type);
  492.       DECL_ARG_TYPE (parm) = type;
  493.       /* We can make this a register, so long as we don't
  494.      accidently complain if someone tries to take its address.  */
  495.       TREE_REGDECL (parm) = 1;
  496.       if (flags != DTOR_FLAG
  497.       && (!flag_this_is_variable || TREE_READONLY (type)))
  498.     TREE_READONLY (parm) = 1;
  499.       TREE_CHAIN (parm) = last_function_parms;
  500.       last_function_parms = parm;
  501.     }
  502.  
  503.   if (flags == DTOR_FLAG)
  504.     {
  505.       tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
  506.       arg_types = hash_tree_chain (const_integer_type, void_list_node);
  507.       name = (char *)alloca (sizeof (DESTRUCTOR_DECL_FORMAT)
  508.                  + IDENTIFIER_LENGTH (cname) + 2);
  509.       sprintf (name, DESTRUCTOR_DECL_FORMAT, IDENTIFIER_POINTER (cname));
  510.       DECL_NAME (function) = get_identifier (name);
  511.       DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
  512.       parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
  513.       TREE_USED (parm) = 1;
  514.       TREE_READONLY (parm) = 1;
  515.       DECL_ARG_TYPE (parm) = const_integer_type;
  516.       /* This is the same chain as DECL_ARGUMENTS (fndecl).  */
  517.       TREE_CHAIN (last_function_parms) = parm;
  518.  
  519.       TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node, arg_types);
  520.       TYPE_HAS_DESTRUCTOR (ctype) = 1;
  521.     }
  522.   else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
  523.     {
  524.       name = (char *)alloca (sizeof (WRAPPER_DECL_FORMAT)
  525.                  + sizeof (ANTI_WRAPPER_DECL_FORMAT)
  526.                  + IDENTIFIER_LENGTH (cname) + 2);
  527.       sprintf (name,
  528.            flags == WRAPPER_FLAG ? WRAPPER_DECL_FORMAT : ANTI_WRAPPER_DECL_FORMAT,
  529.            IDENTIFIER_POINTER (cname));
  530.       DECL_NAME (function) = build_decl_overload (name, arg_types, 1);
  531.       DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
  532.       sprintf (name, flags == WRAPPER_FLAG ? WRAPPER_NAME_FORMAT : ANTI_WRAPPER_NAME_FORMAT,
  533.            IDENTIFIER_POINTER (cname));
  534.       DECL_ORIGINAL_NAME (function) = fn_name = get_identifier (name);
  535.     }
  536.   else if (flags == WRAPPER_PRED_FLAG)
  537.     {
  538.       name = (char *)alloca (sizeof (WRAPPER_PRED_DECL_FORMAT)
  539.                  + sizeof (WRAPPER_PRED_NAME_FORMAT)
  540.                  + IDENTIFIER_LENGTH (cname) + 2);
  541.       sprintf (name, WRAPPER_PRED_DECL_FORMAT, IDENTIFIER_POINTER (cname));
  542.       DECL_NAME (function) = build_decl_overload (name, arg_types, 1);
  543.       DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
  544.       sprintf (name, WRAPPER_PRED_NAME_FORMAT, IDENTIFIER_POINTER (cname));
  545.       DECL_ORIGINAL_NAME (function) = fn_name = get_identifier (name);
  546.     }
  547.   else
  548.     {
  549.       tree these_arg_types;
  550.  
  551.       if (TYPE_DYNAMIC (ctype) && DECL_CONSTRUCTOR_P (function))
  552.     {
  553.       arg_types = hash_tree_chain (build_pointer_type (ptr_type_node),
  554.                        TREE_CHAIN (arg_types));
  555.       TREE_TYPE (function)
  556.         = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
  557.       arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
  558.     }
  559.  
  560.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
  561.     {
  562.       arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
  563.       TREE_TYPE (function)
  564.         = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
  565.       arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
  566.     }
  567.  
  568.       these_arg_types = arg_types;
  569.  
  570.       if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
  571.     /* Only true for static member functions.  */
  572.     these_arg_types = hash_tree_chain (TYPE_POINTER_TO (ctype), arg_types);
  573.  
  574.       DECL_NAME (function) = build_decl_overload (IDENTIFIER_POINTER (fn_name),
  575.                           these_arg_types,
  576.                           1 + DECL_CONSTRUCTOR_P (function));
  577.       DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
  578.       if (flags == TYPENAME_FLAG)
  579.     TREE_TYPE (DECL_NAME (function)) = TREE_TYPE (fn_name);
  580.     }
  581.  
  582.   DECL_ARGUMENTS (function) = last_function_parms;
  583.  
  584.   /* now, the sanity check: report error if this function is not
  585.      really a member of the class it is supposed to belong to.  */
  586.   if (complain)
  587.     {
  588.       tree field;
  589.       int need_quotes = 0;
  590.       char *err_name;
  591.       tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
  592.       tree *methods = 0;
  593.       tree *end = 0;
  594.  
  595.       if (method_vec != 0)
  596.     {
  597.       methods = &TREE_VEC_ELT (method_vec, 0);
  598.       end = TREE_VEC_END (method_vec);
  599.  
  600.       if (*methods == 0)
  601.         methods++;
  602.  
  603.       while (methods != end)
  604.         {
  605.           if (fn_name == DECL_ORIGINAL_NAME (*methods))
  606.         {
  607.           field = *methods;
  608.           while (field)
  609.             {
  610.               if (DECL_NAME (function) == DECL_NAME (field))
  611.             return;
  612.               field = TREE_CHAIN (field);
  613.             }
  614.           break;    /* loser */
  615.         }
  616.           methods++;
  617.         }
  618.     }
  619.  
  620.       if (OPERATOR_NAME_P (fn_name))
  621.     {
  622.       err_name = (char *)alloca (1024);
  623.       sprintf (err_name, "`operator %s'", operator_name_string (fn_name));
  624.     }
  625.       else if (OPERATOR_TYPENAME_P (fn_name))
  626.     if (complain && TYPE_HAS_CONVERSION (ctype))
  627.       err_name = "such type conversion operator";
  628.     else
  629.       err_name = "type conversion operator";
  630.       else if (flags == WRAPPER_FLAG)
  631.     err_name = "wrapper";
  632.       else if (flags == WRAPPER_PRED_FLAG)
  633.     err_name = "wrapper predicate";
  634.       else
  635.     {
  636.       err_name = IDENTIFIER_POINTER (fn_name);
  637.       need_quotes = 1;
  638.     }
  639.  
  640.       if (methods != end)
  641.     if (need_quotes)
  642.       error ("argument list for `%s' does not match any in class", err_name);
  643.     else
  644.       error ("argument list for %s does not match any in class", err_name);
  645.       else
  646.     {
  647.       methods = 0;
  648.       if (need_quotes)
  649.         error ("no `%s' member function declared in class", err_name);
  650.       else
  651.         error ("no %s declared in class", err_name);
  652.     }
  653.  
  654.       /* If we did not find the method in the class, add it to
  655.      avoid spurious errors.  */
  656.       add_method (ctype, methods, function);
  657.     }
  658. }
  659.  
  660. /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
  661.    of a structure component, returning a FIELD_DECL node.
  662.    QUALS is a list of type qualifiers for this decl (such as for declaring
  663.    const member functions).
  664.  
  665.    This is done during the parsing of the struct declaration.
  666.    The FIELD_DECL nodes are chained together and the lot of them
  667.    are ultimately passed to `build_struct' to make the RECORD_TYPE node.
  668.  
  669.    C++:
  670.  
  671.    If class A defines that certain functions in class B are friends, then
  672.    the way I have set things up, it is B who is interested in permission
  673.    granted by A.  However, it is in A's context that these declarations
  674.    are parsed.  By returning a void_type_node, class A does not attempt
  675.    to incorporate the declarations of the friends within its structure.
  676.  
  677.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  678.    CHANGES TO CODE IN `start_method'.  */
  679.  
  680. tree
  681. grokfield (declarator, declspecs, raises, init, asmspec_tree)
  682.      tree declarator, declspecs, raises, init;
  683.      tree asmspec_tree;
  684. {
  685.   register tree value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
  686.   char *asmspec = 0;
  687.  
  688.   if (! value) return NULL_TREE; /* friends went bad.  */
  689.  
  690.   /* Pass friendly classes back.  */
  691.   if (TREE_CODE (value) == VOID_TYPE)
  692.     return void_type_node;
  693.  
  694.   if (DECL_NAME (value) != NULL_TREE
  695.       && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
  696.       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
  697.     error_with_decl (value, "member `%s' conflicts with virtual function table field name");
  698.  
  699.   /* Stash away type declarations.  */
  700.   if (TREE_CODE (value) == TYPE_DECL)
  701.     {
  702.       TREE_NONLOCAL (value) = 1;
  703.       CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
  704.       pushdecl_class_level (value);
  705.       return value;
  706.     }
  707.  
  708.   if (DECL_IN_AGGR_P (value))
  709.     {
  710.       error_with_decl (value, "`%s' is already defined in aggregate scope");
  711.       return void_type_node;
  712.     }
  713.  
  714.   if (asmspec_tree)
  715.     asmspec = TREE_STRING_POINTER (asmspec_tree);
  716.  
  717.   if (init != 0)
  718.     {
  719.       if (TREE_CODE (value) == FUNCTION_DECL)
  720.     {
  721.       grok_function_init (value, init);
  722.       init = NULL_TREE;
  723.     }
  724.       else if (pedantic
  725.            && ! TREE_STATIC (value)
  726.            && ! TREE_READONLY (value))
  727.     {
  728.       error ("fields cannot have initializers");
  729.       init = error_mark_node;
  730.     }
  731.       else
  732.     {
  733.       /* We allow initializers to become parameters to base initializers.  */
  734.       if (TREE_CODE (init) == CONST_DECL)
  735.         init = DECL_INITIAL (init);
  736.       else if (TREE_READONLY_DECL_P (init))
  737.         init = decl_constant_value (init);
  738.       else if (TREE_CODE (init) == CONSTRUCTOR)
  739.         init = digest_init (TREE_TYPE (value), init, 0);
  740.       assert (TREE_PERMANENT (init));
  741.       if (init == error_mark_node)
  742.         /* We must make this look different than `error_mark_node'
  743.            because `decl_const_value' would mis-interpret it
  744.            as only meaning that this VAR_DECL is defined.  */
  745.         init = build1 (NOP_EXPR, TREE_TYPE (value), init);
  746.       else if (! TREE_LITERAL (init))
  747.         {
  748.           /* We can allow references to things that are effectively
  749.          static, since references are initialized with the address.  */
  750.           if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
  751.           || (TREE_EXTERNAL (init) == 0
  752.               && TREE_STATIC (init) == 0))
  753.         {
  754.           error ("field initializer is not constant");
  755.           init = error_mark_node;
  756.         }
  757.         }
  758.     }
  759.     }
  760.  
  761.   if (TREE_CODE (value) == VAR_DECL)
  762.     {
  763.       /* We cannot call pushdecl here, because that would
  764.      fill in the value of our TREE_CHAIN.  Instead, we
  765.      modify finish_decl to do the right thing, namely, to
  766.      put this decl out straight away.  */
  767.       if (TREE_STATIC (value))
  768.     {
  769.       if (asmspec == 0)
  770.         {
  771.           char *buf
  772.         = (char *)alloca (IDENTIFIER_LENGTH (current_class_name)
  773.                   + IDENTIFIER_LENGTH (DECL_NAME (value))
  774.                   + sizeof (STATIC_NAME_FORMAT));
  775.           tree name;
  776.  
  777.           sprintf (buf, STATIC_NAME_FORMAT,
  778.                IDENTIFIER_POINTER (current_class_name),
  779.                IDENTIFIER_POINTER (DECL_NAME (value)));
  780.           name = get_identifier (buf);
  781.           TREE_PUBLIC (value) = 1;
  782.           DECL_INITIAL (value) = error_mark_node;
  783.           asmspec = IDENTIFIER_POINTER (name);
  784.           DECL_ASSEMBLER_NAME (value) = asmspec;
  785.           asmspec_tree = build_string (IDENTIFIER_LENGTH (name), asmspec);
  786.         }
  787.       pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
  788.  
  789.       /* Static consts need not be initialized in the class definition.  */
  790.       if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
  791.         {
  792.           static int explanation = 0;
  793.  
  794.           error ("initializer invalid for static member with constructor");
  795.           if (explanation++ == 0)
  796.         error ("(you really want to initialize it separately)");
  797.           init = 0;
  798.         }
  799.       /* Force the user to know when an uninitialized static
  800.          member is being used.  */
  801.       if (TREE_READONLY (value)
  802.           && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
  803.         TREE_EXTERNAL (value) = 1;
  804.     }
  805.       DECL_INITIAL (value) = init;
  806.       DECL_IN_AGGR_P (value) = 1;
  807.       finish_decl (value, init, asmspec_tree);
  808.       pushdecl_class_level (value);
  809.       return value;
  810.     }
  811.   if (TREE_CODE (value) == FIELD_DECL)
  812.     {
  813.       DECL_ASSEMBLER_NAME (value) = asmspec;
  814.       if (DECL_INITIAL (value) == error_mark_node)
  815.     init = error_mark_node;
  816.       finish_decl (value, init, asmspec_tree);
  817.       DECL_INITIAL (value) = init;
  818.       DECL_IN_AGGR_P (value) = 1;
  819.       return value;
  820.     }
  821.   if (TREE_CODE (value) == FUNCTION_DECL)
  822.     {
  823.       /* grokdeclarator defers setting this.  */
  824.       TREE_PUBLIC (value) = 1;
  825.       if (TREE_CHAIN (value) != NULL_TREE)
  826.     {
  827.       /* Need a fresh node here so that we don't get circularity
  828.          when we link these together.  */
  829.       value = copy_node (value);
  830.       /* When does this happen?  */
  831.       assert (init == NULL_TREE);
  832.     }
  833.       finish_decl (value, init, asmspec_tree);
  834.  
  835.       /* Pass friends back this way.  */
  836.       if (DECL_FRIEND_P (value))
  837.     return void_type_node;
  838.  
  839.       DECL_IN_AGGR_P (value) = 1;
  840.       return value;
  841.     }
  842.   abort ();
  843. }
  844.  
  845. /* Like `grokfield', but for bitfields.
  846.    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.  */
  847.  
  848. tree
  849. grokbitfield (declarator, declspecs, width)
  850.      tree declarator, declspecs, width;
  851. {
  852.   register tree value = grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
  853.  
  854.   if (! value) return NULL_TREE; /* friends went bad.  */
  855.  
  856.   /* Pass friendly classes back.  */
  857.   if (TREE_CODE (value) == VOID_TYPE)
  858.     return void_type_node;
  859.  
  860.   if (TREE_CODE (value) == TYPE_DECL)
  861.     {
  862.       error_with_decl (value, "cannot declare `%s' to be a bitfield type");
  863.       return NULL_TREE;
  864.     }
  865.  
  866.   if (DECL_IN_AGGR_P (value))
  867.     {
  868.       error_with_decl (value, "`%s' is already defined in aggregate scope");
  869.       return void_type_node;
  870.     }
  871.  
  872. #ifdef FIELD_XREF
  873.   FIELD_xref_member(current_class_name,value);
  874. #endif
  875.  
  876.   if (TREE_STATIC (value))
  877.     {
  878.       error_with_decl (value, "static member `%s' cannot be a bitfield");
  879.       return NULL_TREE;
  880.     }
  881.   if (TREE_CODE (value) == FIELD_DECL)
  882.     {
  883.       finish_decl (value, NULL_TREE, NULL_TREE);
  884.       /* detect invalid field size.  */
  885.       if (TREE_CODE (width) == CONST_DECL)
  886.     width = DECL_INITIAL (width);
  887.       else if (TREE_READONLY_DECL_P (width))
  888.     width = decl_constant_value (width);
  889.  
  890.       if (TREE_CODE (width) != INTEGER_CST)
  891.     {
  892.       error_with_decl (value, "structure field `%s' width not an integer constant");
  893.       DECL_INITIAL (value) = NULL;
  894.     }
  895.       else
  896.     {
  897.       DECL_INITIAL (value) = width;
  898.       TREE_PACKED (value) = 1;
  899.     }
  900.       DECL_IN_AGGR_P (value) = 1;
  901.       return value;
  902.     }
  903.   abort ();
  904. }
  905.  
  906. /* Like GROKFIELD, except that the declarator has been
  907.    buried in DECLSPECS.  Find the declarator, and
  908.    return something that looks like it came from
  909.    GROKFIELD.  */
  910. tree
  911. groktypefield (declspecs, parmlist)
  912.      tree declspecs;
  913.      tree parmlist;
  914. {
  915.   tree spec = declspecs;
  916.   tree prev = NULL_TREE;
  917.  
  918.   tree type_id = NULL_TREE;
  919.   tree quals = NULL_TREE;
  920.   tree lengths = NULL_TREE;
  921.   tree decl = NULL_TREE;
  922.  
  923.   while (spec)
  924.     {
  925.       register tree id = TREE_VALUE (spec);
  926.  
  927.       if (TREE_CODE (spec) != TREE_LIST)
  928.     /* Certain parse errors slip through.  For example,
  929.        `int class ();' is not caught by the parser. Try
  930.        weakly to recover here.  */
  931.     return NULL_TREE;
  932.  
  933.       if (TREE_CODE (id) == TYPE_DECL
  934.       || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
  935.     {
  936.       /* We have a constructor/destructor or
  937.          conversion operator.  Use it.  */
  938.       if (prev)
  939.         TREE_CHAIN (prev) = TREE_CHAIN (spec);
  940.       else
  941.         {
  942.           declspecs = TREE_CHAIN (spec);
  943.         }
  944.       type_id = id;
  945.       goto found;
  946.     }
  947.       prev = spec;
  948.       spec = TREE_CHAIN (spec);
  949.     }
  950.  
  951.   /* Nope, we have a conversion operator to a scalar type.  */
  952.   spec = declspecs;
  953.   while (spec)
  954.     {
  955.       tree id = TREE_VALUE (spec);
  956.  
  957.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  958.     {
  959.       if (id == ridpointers[(int)RID_INT]
  960.           || id == ridpointers[(int)RID_DOUBLE]
  961.           || id == ridpointers[(int)RID_FLOAT])
  962.         {
  963.           if (type_id)
  964.         error ("extra `%s' ignored",
  965.                IDENTIFIER_POINTER (id));
  966.           else
  967.         type_id = id;
  968.         }
  969.       else if (id == ridpointers[(int)RID_LONG]
  970.            || id == ridpointers[(int)RID_SHORT]
  971.            || id == ridpointers[(int)RID_CHAR])
  972.         {
  973.           lengths = tree_cons (NULL_TREE, id, lengths);
  974.         }
  975.       else if (id == ridpointers[(int)RID_VOID])
  976.         {
  977.           if (type_id)
  978.         error ("spurious `void' type ignored");
  979.           else
  980.         error ("conversion to `void' type invalid");
  981.         }
  982.       else if (id == ridpointers[(int)RID_AUTO]
  983.            || id == ridpointers[(int)RID_REGISTER]
  984.            || id == ridpointers[(int)RID_TYPEDEF]
  985.            || id == ridpointers[(int)RID_CONST]
  986.            || id == ridpointers[(int)RID_VOLATILE])
  987.         {
  988.           error ("type specifier `%s' used invalidly",
  989.              IDENTIFIER_POINTER (id));
  990.         }
  991.       else if (id == ridpointers[(int)RID_FRIEND]
  992.            || id == ridpointers[(int)RID_VIRTUAL]
  993.            || id == ridpointers[(int)RID_INLINE]
  994.            || id == ridpointers[(int)RID_UNSIGNED]
  995.            || id == ridpointers[(int)RID_SIGNED]
  996.            || id == ridpointers[(int)RID_STATIC]
  997.            || id == ridpointers[(int)RID_EXTERN])
  998.         {
  999.           quals = tree_cons (NULL_TREE, id, quals);
  1000.         }
  1001.       else
  1002.         {
  1003.           /* Happens when we have a global typedef
  1004.          and a class-local member function with
  1005.          the same name.  */
  1006.           type_id = id;
  1007.           goto found;
  1008.         }
  1009.     }
  1010.       else if (TREE_CODE (id) == RECORD_TYPE)
  1011.     {
  1012.       type_id = TYPE_NAME (id);
  1013.       if (TREE_CODE (type_id) == TYPE_DECL)
  1014.         type_id = DECL_NAME (type_id);
  1015.       if (type_id == NULL_TREE)
  1016.         error ("identifier for aggregate type conversion omitted");
  1017.     }
  1018.       else
  1019.     assert (0);
  1020.       spec = TREE_CHAIN (spec);
  1021.     }
  1022.  
  1023.   if (type_id)
  1024.     {
  1025.       declspecs = chainon (lengths, quals);
  1026.     }
  1027.   else if (lengths)
  1028.     {
  1029.       if (TREE_CHAIN (lengths))
  1030.     error ("multiple length specifiers");
  1031.       type_id = ridpointers[(int)RID_INT];
  1032.       declspecs = chainon (lengths, quals);
  1033.     }
  1034.   else if (quals)
  1035.     {
  1036.       error ("no type given, defaulting to `operator int ...'");
  1037.       type_id = ridpointers[(int)RID_INT];
  1038.       declspecs = quals;
  1039.     }
  1040.   else return NULL_TREE;
  1041.  found:
  1042.   decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
  1043.              declspecs, FIELD, 0, NULL_TREE);
  1044.   if (decl == NULL_TREE)
  1045.     return NULL_TREE;
  1046.  
  1047.   if (TREE_CODE (decl) == FUNCTION_DECL && TREE_CHAIN (decl) != NULL_TREE)
  1048.     {
  1049.       /* Need a fresh node here so that we don't get circularity
  1050.      when we link these together.  */
  1051.       decl = copy_node (decl);
  1052.     }
  1053.  
  1054.   if (decl == void_type_node
  1055.       || (TREE_CODE (decl) == FUNCTION_DECL
  1056.       && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
  1057.     /* bunch of friends.  */
  1058.     return decl;
  1059.  
  1060.   if (DECL_IN_AGGR_P (decl))
  1061.     {
  1062.       error_with_decl (decl, "`%s' already defined in aggregate scope");
  1063.       return void_type_node;
  1064.     }
  1065.  
  1066.   finish_decl (decl, NULL_TREE, NULL_TREE);
  1067.  
  1068.   /* If this declaration is common to another declaration
  1069.      complain about such redundancy, and return NULL_TREE
  1070.      so that we don't build a circular list.  */
  1071.   if (TREE_CHAIN (decl))
  1072.     {
  1073.       error_with_decl (decl, "function `%s' declared twice in aggregate");
  1074.       return NULL_TREE;
  1075.     }
  1076.   DECL_IN_AGGR_P (decl) = 1;
  1077.   return decl;
  1078. }
  1079.  
  1080. /* The precedence rules of this grammar (or any other deterministic LALR
  1081.    grammar, for that matter), place the CALL_EXPR somewhere where we
  1082.    may not want it.  The solution is to grab the first CALL_EXPR we see,
  1083.    pretend that that is the one that belongs to the parameter list of
  1084.    the type conversion function, and leave everything else alone.
  1085.    We pull it out in place.
  1086.  
  1087.    CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR
  1088.    does not appear in DECL.  */
  1089. tree
  1090. grokoptypename (decl, call_required)
  1091.      tree decl;
  1092.      int call_required;
  1093. {
  1094.   tree tmp, last;
  1095.  
  1096.   assert (TREE_CODE (decl) == TYPE_EXPR);
  1097.  
  1098.   tmp = TREE_OPERAND (decl, 0);
  1099.   last = NULL_TREE;
  1100.  
  1101.   while (tmp)
  1102.     {
  1103.       switch (TREE_CODE (tmp))
  1104.     {
  1105.     case CALL_EXPR:
  1106.       {
  1107.         tree parms = TREE_OPERAND (tmp, 1);
  1108.  
  1109.         if (last)
  1110.           TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
  1111.         else
  1112.           TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0);
  1113.         if (parms
  1114.         && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST)
  1115.           TREE_VALUE (parms)
  1116.         = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)),
  1117.                   TREE_PURPOSE (TREE_VALUE (parms)),
  1118.                   TYPENAME, 0, NULL_TREE);
  1119.         if (parms)
  1120.           {
  1121.         if (TREE_VALUE (parms) != void_type_node)
  1122.           error ("operator <typename> requires empty parameter list");
  1123.         else
  1124.           /* Canonicalize parameter lists.  */
  1125.           TREE_OPERAND (tmp, 1) = void_list_node;
  1126.           }
  1127.  
  1128.         last = grokdeclarator (TREE_OPERAND (decl, 0),
  1129.                    TREE_TYPE (decl),
  1130.                    TYPENAME, 0, NULL_TREE);
  1131.         TREE_OPERAND (tmp, 0) = build_typename_overload (last);
  1132.         TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
  1133.         return tmp;
  1134.       }
  1135.  
  1136.     case INDIRECT_REF:
  1137.     case ADDR_EXPR:
  1138.     case ARRAY_REF:
  1139.       break;
  1140.  
  1141.     case SCOPE_REF:
  1142.       /* This is legal when declaring a conversion to
  1143.          something of type pointer-to-member.  */
  1144.       if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF)
  1145.         {
  1146.           tmp = TREE_OPERAND (tmp, 1);
  1147.         }
  1148.       else
  1149.         {
  1150. #if 0
  1151.           /* We may need to do this if grokdeclarator cannot handle this.  */
  1152.           error ("type `member of class %s' invalid return type",
  1153.              TYPE_NAME_STRING (TREE_OPERAND (tmp, 0)));
  1154.           TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1));
  1155. #endif
  1156.           tmp = TREE_OPERAND (tmp, 1);
  1157.         }
  1158.       break;
  1159.  
  1160.     default:
  1161.       assert (0);
  1162.     }
  1163.       last = tmp;
  1164.       tmp = TREE_OPERAND (tmp, 0);
  1165.     }
  1166.  
  1167.   if (call_required)
  1168.     error ("operator <typename> construct requires parameter list");
  1169.  
  1170.   last = grokdeclarator (TREE_OPERAND (decl, 0),
  1171.              TREE_TYPE (decl),
  1172.              TYPENAME, 0, NULL_TREE);
  1173.   tmp = build_parse_node (CALL_EXPR, build_typename_overload (last),
  1174.               void_list_node, NULL_TREE);
  1175.   TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
  1176.   return tmp;
  1177. }
  1178.  
  1179. /* Given an encoding for an operator name (see parse.y, the rules
  1180.    for making an `operator_name' in the variable DECLARATOR,
  1181.    return the name of the operator prefix as an IDENTIFIER_NODE.
  1182.  
  1183.    CTYPE is the class type to which this operator belongs.
  1184.    Needed in case it is a static member function.
  1185.  
  1186.    TYPE, if nonnull, is the function type for this declarator.
  1187.    This information helps to resolve potential ambiguities.
  1188.  
  1189.    If REPORT_AMBIGUOUS is non-zero, an error message
  1190.    is reported, and a default arity of the operator is
  1191.    returned.  Otherwise, return the operator under an OP_EXPR,
  1192.    for later evaluation when type information will enable
  1193.    proper instantiation.
  1194.  
  1195.    IS_DECL is 1 if this is a decl (as opposed to an expression).
  1196.    IS_DECL is 2 if this is a static function decl.
  1197.    Otherwise IS_DECL is 0.  */
  1198. tree
  1199. grokopexpr (declp, ctype, type, report_ambiguous, is_decl)
  1200.      tree *declp;
  1201.      tree ctype, type;
  1202.      int report_ambiguous;
  1203. {
  1204.   tree declarator = *declp;
  1205.   tree name, parmtypes;
  1206.   int seen_classtype_parm
  1207.     = (type != NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  1208.       || is_decl == 2;
  1209.  
  1210.   if (type != NULL_TREE)
  1211.     {
  1212.       if (ctype == 0 && TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR)
  1213.     {
  1214.       if (TYPE_ARG_TYPES (type)
  1215.           && TREE_CHAIN (TYPE_ARG_TYPES (type))
  1216.           && TREE_CHAIN (TYPE_ARG_TYPES (type)) != void_list_node)
  1217.         return get_identifier (OPERATOR_NEW_FORMAT);
  1218.       return get_identifier ("__builtin_new");
  1219.     }
  1220.       else if (ctype == 0 && TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR)
  1221.     return get_identifier ("__builtin_delete");
  1222.       else
  1223.     {
  1224.       /* Now we know the number of parameters,
  1225.          so build the real operator fnname.  */
  1226.       parmtypes = TYPE_ARG_TYPES (type);
  1227.       if (is_decl > 1 && TREE_CODE (type) == METHOD_TYPE)
  1228.         parmtypes = TREE_CHAIN (parmtypes);
  1229.       name = build_operator_fnname (declp, parmtypes, is_decl > 1);
  1230.       declarator = *declp;
  1231.     }
  1232.     }
  1233.   else
  1234.     {
  1235.       if (TREE_PURPOSE (declarator) == NULL_TREE)
  1236.     switch (TREE_CODE (TREE_VALUE (declarator)))
  1237.       {
  1238.       case PLUS_EXPR:
  1239.       case CONVERT_EXPR:
  1240.       case ADDR_EXPR:
  1241.       case BIT_AND_EXPR:
  1242.       case INDIRECT_REF:
  1243.       case MULT_EXPR:
  1244.       case NEGATE_EXPR:
  1245.       case MINUS_EXPR:
  1246.         if (report_ambiguous)
  1247.           {
  1248.         error ("operator '%s' ambiguous, (default binary)",
  1249.                opname_tab[(int)TREE_CODE (TREE_VALUE (declarator))]);
  1250.         name = build_operator_fnname (declp, NULL_TREE, 2);
  1251.         declarator = *declp;
  1252.           }
  1253.         else
  1254.           {
  1255.         /* do something intellegent.  */
  1256.         TREE_TYPE (declarator) = unknown_type_node;
  1257.         return declarator;
  1258.           }
  1259.         break;
  1260.       default:
  1261.         name = build_operator_fnname (declp, NULL_TREE, -1);
  1262.         declarator = *declp;
  1263.         break;
  1264.       }
  1265.       else if (TREE_CODE (TREE_PURPOSE (declarator)) == MODIFY_EXPR)
  1266.     {
  1267.       name = build_operator_fnname (declp, NULL_TREE, -1);
  1268.       declarator = *declp;
  1269.     }
  1270.       else abort ();
  1271.     }
  1272.   /* Now warn if the parameter list does not contain any args
  1273.      which are of aggregate type.  */
  1274.   if (is_decl && type != NULL_TREE && ! seen_classtype_parm)
  1275.     for (parmtypes = TYPE_ARG_TYPES (type);
  1276.      parmtypes;
  1277.      parmtypes = TREE_CHAIN (parmtypes))
  1278.       if (IS_AGGR_TYPE (TREE_VALUE (parmtypes))
  1279.       || (TREE_CODE (TREE_VALUE (parmtypes)) == REFERENCE_TYPE
  1280.           && IS_AGGR_TYPE (TREE_TYPE (TREE_VALUE (parmtypes)))))
  1281.     {
  1282.       seen_classtype_parm = 1;
  1283.       break;
  1284.     }
  1285.  
  1286.   if (is_decl && seen_classtype_parm == 0)
  1287.     if (TREE_CODE (declarator) == OP_IDENTIFIER
  1288.     && (TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR
  1289.         || TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR))
  1290.       /* Global operators new and delete are not overloaded.  */
  1291.       TREE_OVERLOADED (name) = 0;
  1292.     else
  1293.       error ("operator has no %suser-defined argument type",
  1294.          type == NULL_TREE ? "(default) " : "");
  1295.  
  1296.   return name;
  1297. }
  1298.  
  1299. /* When a function is declared with an initialializer,
  1300.    do the right thing.  Currently, there are two possibilities:
  1301.  
  1302.    class B
  1303.    {
  1304.     public:
  1305.      // initialization possibility #1.
  1306.      virtual void f () = 0;
  1307.      int g ();
  1308.    };
  1309.    
  1310.    class D1 : B
  1311.    {
  1312.     public:
  1313.      int d1;
  1314.      // error, no f ();
  1315.    };
  1316.    
  1317.    class D2 : B
  1318.    {
  1319.     public:
  1320.      int d2;
  1321.      void f ();
  1322.    };
  1323.    
  1324.    class D3 : B
  1325.    {
  1326.     public:
  1327.      int d3;
  1328.      // initialization possibility #2
  1329.      void f () = B::f;
  1330.    };
  1331.  
  1332. */
  1333.  
  1334. static void
  1335. grok_function_init (decl, init)
  1336.      tree decl;
  1337.      tree init;
  1338. {
  1339.   /* An initializer for a function tells how this function should
  1340.      be inherited.  */
  1341.   tree type = TREE_TYPE (decl);
  1342.   extern tree abort_fndecl;
  1343.  
  1344.   if (TREE_CODE (type) == FUNCTION_TYPE)
  1345.     error_with_decl (decl, "initializer specified for non-member function `%s'");
  1346.   else if (! DECL_VIRTUAL_P (decl))
  1347.     error_with_decl (decl, "initializer specified for non-virtual method `%s'");
  1348.   else if (integer_zerop (init))
  1349.     {
  1350.       /* Mark this function as being "defined".  */
  1351.       DECL_INITIAL (decl) = error_mark_node;
  1352.       /* Give this node rtl from `abort'.  */
  1353.       DECL_RTL (decl) = DECL_RTL (abort_fndecl);
  1354.       DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
  1355.     }
  1356.   else if (TREE_CODE (init) == OFFSET_REF
  1357.        && TREE_OPERAND (init, 0) == NULL_TREE
  1358.        && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
  1359.     {
  1360.       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (init));
  1361.       tree basefn = TREE_OPERAND (init, 1);
  1362.       if (TREE_CODE (basefn) != FUNCTION_DECL)
  1363.     error_with_decl (decl, "non-method initializer invalid for method `%s'");
  1364.       else if (DECL_OFFSET (TYPE_NAME (basefn)) != 0)
  1365.     sorry ("base member function from other than first base class");
  1366.       else
  1367.     {
  1368.       basetype = get_base_type (basetype, TYPE_METHOD_BASETYPE (type), 1);
  1369.       if (basetype == error_mark_node)
  1370.         ;
  1371.       else if (basetype == 0)
  1372.         error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
  1373.                  TYPE_METHOD_BASETYPE (type));
  1374.       else
  1375.         {
  1376.           /* Mark this function as being defined,
  1377.          and give it new rtl.  */
  1378.           DECL_INITIAL (decl) = error_mark_node;
  1379.           DECL_RTL (decl) = DECL_RTL (basefn);
  1380.         }
  1381.     }
  1382.     }
  1383.   else
  1384.     error_with_decl (decl, "invalid initializer for virtual method `%s'");
  1385. }
  1386.  
  1387. /* Cache the value of this class's main virtual function table pointer
  1388.    in a register variable.  This will save one indirection if a
  1389.    more than one virtual function call is made this function.  */
  1390. void
  1391. setup_vtbl_ptr ()
  1392. {
  1393.   extern struct rtx_def *base_init_insns;
  1394.  
  1395.   if (base_init_insns == 0
  1396.       && DECL_CONSTRUCTOR_P (current_function_decl))
  1397.     emit_base_init (current_class_type, 0);
  1398.  
  1399.   if ((flag_this_is_variable & 1) == 0
  1400.       && optimize
  1401.       && current_class_type
  1402.       && CLASSTYPE_VSIZE (current_class_type)
  1403.       && ! DECL_STATIC_FUNCTION_P (current_function_decl))
  1404.     {
  1405.       tree vfield = build_vfield_ref (C_C_D, current_class_type);
  1406.       current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
  1407.       DECL_RTL (current_vtable_decl) = 0;
  1408.       DECL_INITIAL (current_vtable_decl) = error_mark_node;
  1409.       /* Have to cast the initializer, since it may have come from a
  1410.      more base class then we ascribe CURRENT_VTABLE_DECL to be.  */
  1411.       finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0);
  1412.       current_vtable_decl = build_indirect_ref (current_vtable_decl, 0);
  1413.     }
  1414.   else
  1415.     current_vtable_decl = NULL_TREE;
  1416. }
  1417.  
  1418. /* Record the existence of an addressable inline function.  */
  1419. void
  1420. mark_inline_for_output (decl)
  1421.      tree decl;
  1422. {
  1423.   pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl,
  1424.                         pending_addressable_inlines);
  1425. }
  1426.  
  1427. void
  1428. clear_temp_name ()
  1429. {
  1430.   temp_name_counter = 0;
  1431. }
  1432.  
  1433. /* Hand off a unique name which can be used for variable we don't really
  1434.    want to know about anyway, for example, the anonymous variables which
  1435.    are needed to make references work.  Declare this thing so we can use it.
  1436.    The variable created will be of type TYPE.
  1437.  
  1438.    STATICP is nonzero if this variable should be static.  */
  1439.  
  1440. tree
  1441. get_temp_name (type, staticp)
  1442.      tree type;
  1443.      int staticp;
  1444. {
  1445.   char buf[sizeof (AUTO_TEMP_FORMAT) + 12];
  1446.   tree decl;
  1447.   int temp = 0;
  1448.   int toplev = global_bindings_p ();
  1449.   if (toplev || staticp)
  1450.     {
  1451.       temp = allocation_temporary_p ();
  1452.       if (temp)
  1453.     end_temporary_allocation ();
  1454.       sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
  1455.       decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
  1456.     }
  1457.   else
  1458.     {
  1459.       sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
  1460.       decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
  1461.     }
  1462.   TREE_USED (decl) = 1;
  1463.   TREE_STATIC (decl) = staticp;
  1464.  
  1465.   /* If this is a local variable, then lay out its rtl now.
  1466.      Otherwise, callers of this function are responsible for dealing
  1467.      with this variable's rtl.  */
  1468.   if (! toplev)
  1469.     {
  1470.       expand_decl (decl);
  1471.       expand_decl_init (decl);
  1472.     }
  1473.   else if (temp)
  1474.     resume_temporary_allocation ();
  1475.  
  1476.   return decl;
  1477. }
  1478.  
  1479. /* Get a variable which we can use for multiple assignments.
  1480.    It is not entered into current_binding_level, because
  1481.    that breaks things when it comes time to do final cleanups
  1482.    (which take place "outside" the binding contour of the function).
  1483.  
  1484.    Because it is not entered into the binding contour, `expand_end_bindings'
  1485.    does not see this variable automatically.  Users of this function
  1486.    must either pass this variable to expand_end_bindings or do
  1487.    themselves what expand_end_bindings was meant to do (like keeping
  1488.    the variable live if -noreg was specified).  */
  1489. tree
  1490. get_temp_regvar (type, init)
  1491.      tree type, init;
  1492. {
  1493.   static char buf[sizeof (AUTO_TEMP_FORMAT) + 8] = { '_' };
  1494.   tree decl;
  1495.  
  1496.   sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
  1497.   decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
  1498.   TREE_USED (decl) = 1;
  1499.   TREE_REGDECL (decl) = 1;
  1500.  
  1501.   if (init)
  1502.     store_init_value (decl, init);
  1503.  
  1504.   /* We can expand these without fear, since they cannot need
  1505.      constructors or destructors.  */
  1506.   expand_decl (decl);
  1507.   expand_decl_init (decl);
  1508.   return decl;
  1509. }
  1510.  
  1511. /* Make the macro TEMP_NAME_P available to units which do not
  1512.    include c-tree.h.  */
  1513. int
  1514. temp_name_p (decl)
  1515.      tree decl;
  1516. {
  1517.   return TEMP_NAME_P (decl);
  1518. }
  1519.  
  1520. /* Finish off the processing of a UNION_TYPE structure.
  1521.    If there are static members, then all members are
  1522.    static, and must be laid out together.  If the
  1523.    union is an anonymous union, we arrage for that
  1524.    as well.  PUBLICP is nonzero if this union is
  1525.    not declared static.  */
  1526. void
  1527. finish_anon_union (anon_union_decl)
  1528.      tree anon_union_decl;
  1529. {
  1530.   tree type = TREE_TYPE (anon_union_decl);
  1531.   tree field, decl;
  1532.   tree elems = NULL_TREE;
  1533.   int public_p = TREE_PUBLIC (anon_union_decl);
  1534.   int static_p = TREE_STATIC (anon_union_decl);
  1535.   int external_p = TREE_EXTERNAL (anon_union_decl);
  1536.  
  1537.   if ((field = TYPE_FIELDS (type)) == NULL_TREE)
  1538.     return;
  1539.  
  1540.   if (public_p && (static_p || external_p))
  1541.     error ("optimizer cannot handle global anonymous unions");
  1542.  
  1543.   while (field)
  1544.     {
  1545.       decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
  1546.       /* tell `pushdecl' that this is not tentative.  */
  1547.       DECL_INITIAL (decl) = error_mark_node;
  1548.       TREE_PUBLIC (decl) = public_p;
  1549.       TREE_STATIC (decl) = static_p;
  1550.       TREE_EXTERNAL (decl) = external_p;
  1551.       decl = pushdecl (decl);
  1552.       DECL_INITIAL (decl) = NULL_TREE;
  1553.       elems = tree_cons (DECL_ASSEMBLER_NAME (field), decl, elems);
  1554.       TREE_TYPE (elems) = type;
  1555.       field = TREE_CHAIN (field);
  1556.     }
  1557.   if (static_p)
  1558.     make_decl_rtl (decl, 0, global_bindings_p ());
  1559.   expand_anon_union_decl (decl, NULL_TREE, elems);
  1560. }
  1561.  
  1562. /* Finish and output a table which is generated by the compiler.
  1563.    NAME is the name to give the table.
  1564.    TYPE is the type of the table entry.
  1565.    INIT is all the elements in the table.
  1566.    PUBLICP is non-zero if this table should be given external visibility.  */
  1567. tree
  1568. finish_table (name, type, init, publicp)
  1569.      tree name, type, init;
  1570. {
  1571.   tree itype, atype, decl;
  1572.  
  1573.   itype = build_index_type (build_int_2 (list_length (init), 0));
  1574.   atype = build_cplus_array_type (type, itype);
  1575.   layout_type (atype);
  1576.   decl = build_decl (VAR_DECL, name, atype);
  1577.   decl = pushdecl (decl);
  1578.   TREE_STATIC (decl) = 1;
  1579.   TREE_PUBLIC (decl) = publicp;
  1580.   init = build (CONSTRUCTOR, atype, NULL_TREE, init);
  1581.   TREE_LITERAL (init) = 1;
  1582.   TREE_STATIC (init) = 1;
  1583.   DECL_INITIAL (decl) = init;
  1584.   finish_decl (decl, init,
  1585.            build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
  1586.                  IDENTIFIER_POINTER (DECL_NAME (decl))));
  1587.   return decl;
  1588. }
  1589.  
  1590. /* Auxilliary functions to make type signatures for
  1591.    `operator new' and `operator delete' correspond to
  1592.    what compiler will be expecting.  */
  1593.  
  1594. extern tree sizetype;
  1595.  
  1596. tree
  1597. coerce_new_type (ctype, type)
  1598.      tree ctype;
  1599.      tree type;
  1600. {
  1601.   int e1 = 0, e2 = 0;
  1602.  
  1603.   if (TREE_CODE (type) == METHOD_TYPE)
  1604.     type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
  1605.   if (TREE_TYPE (type) != ptr_type_node)
  1606.     e1 = 1, error ("`operator new' must return type `void *'");
  1607.  
  1608.   /* Technically the type must be `size_t', but we may not know
  1609.      what that is.  */
  1610.   if (TYPE_ARG_TYPES (type) == NULL_TREE)
  1611.     e1 = 1, error ("`operator new' takes type `size_t' parameter");
  1612.   else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
  1613.        || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
  1614.     e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
  1615.   if (e2)
  1616.     type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
  1617.   else if (e1)
  1618.     type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
  1619.   return type;
  1620. }
  1621.  
  1622. tree
  1623. coerce_delete_type (ctype, type)
  1624.      tree ctype;
  1625.      tree type;
  1626. {
  1627.   int e1 = 0, e2 = 0, e3 = 0;
  1628.   tree arg_types = TYPE_ARG_TYPES (type);
  1629.  
  1630.   if (TREE_CODE (type) == METHOD_TYPE)
  1631.     {
  1632.       type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
  1633.       arg_types = TREE_CHAIN (arg_types);
  1634.     }
  1635.   if (TREE_TYPE (type) != void_type_node)
  1636.     e1 = 1, error ("`operator delete' must return type `void'");
  1637.   if (arg_types == NULL_TREE
  1638.       || TREE_VALUE (arg_types) != ptr_type_node)
  1639.     e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
  1640.  
  1641.   if (arg_types
  1642.       && TREE_CHAIN (arg_types)
  1643.       && TREE_CHAIN (arg_types) != void_list_node)
  1644.     {
  1645.       /* Again, technically this argument must be `size_t', but again
  1646.      we may not know what that is.  */
  1647.       tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
  1648.       if (TREE_CODE (t2) != INTEGER_TYPE
  1649.       || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
  1650.     e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
  1651.       else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
  1652.     {
  1653.       e3 = 1;
  1654.       if (TREE_CHAIN (TREE_CHAIN (arg_types)))
  1655.         error ("too many arguments in declaration of `operator delete'");
  1656.       else
  1657.         error ("`...' invalid in specification of `operator delete'");
  1658.     }
  1659.     }
  1660.   if (e3)
  1661.     arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
  1662.   else if (e3 |= e2)
  1663.     {
  1664.       if (arg_types == NULL_TREE)
  1665.     arg_types = void_list_node;
  1666.       else
  1667.     arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
  1668.     }
  1669.   else e3 |= e1;
  1670.  
  1671.   if (e3)
  1672.     type = build_function_type (void_type_node, arg_types);
  1673.  
  1674.   return type;
  1675. }
  1676.  
  1677. static void
  1678. write_vtable_entries (decl)
  1679.      tree decl;
  1680. {
  1681.   tree entries;
  1682.  
  1683.   for (entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
  1684.        entries; entries = TREE_CHAIN (entries))
  1685.     {
  1686.       tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
  1687.       tree fn = TREE_OPERAND (fnaddr, 0);
  1688.       if (! TREE_ASM_WRITTEN (fn)
  1689.       && DECL_SAVED_INSNS (fn))
  1690.     {
  1691.       if (TREE_PUBLIC (DECL_CONTEXT (fn)))
  1692.         TREE_PUBLIC (fn) = 1;
  1693.       TREE_ADDRESSABLE (fn) = 1;
  1694.       output_inline_function (fn);
  1695.     }
  1696.     }
  1697. }
  1698.  
  1699. static void
  1700. finish_vtable_typedecl (prev, vars)
  1701.      tree prev, vars;
  1702. {
  1703.   tree decl = CLASS_ASSOC_VTABLE (TREE_TYPE (vars));
  1704.  
  1705.   /* If we are controlled by `+e2', obey.  */
  1706.   if (write_virtuals == 2)
  1707.     {
  1708.       tree assoc = value_member (DECL_NAME (vars), pending_vtables);
  1709.       if (assoc)
  1710.     TREE_PURPOSE (assoc) = void_type_node;
  1711.       else
  1712.     decl = NULL_TREE;
  1713.     }
  1714.   /* If this type has inline virtual functions, then
  1715.      write those functions out now.  */
  1716.   if (decl && (TREE_PUBLIC (decl)
  1717.            || (! TREE_EXTERNAL (decl) && TREE_USED (decl))))
  1718.     write_vtable_entries (decl);
  1719. }
  1720.  
  1721. static void
  1722. finish_vtable_vardecl (prev, vars)
  1723.      tree prev, vars;
  1724. {
  1725.   if (write_virtuals < 0)
  1726.     ;
  1727.   else if (write_virtuals == 0
  1728.        ? TREE_USED (vars)
  1729.        : (TREE_PUBLIC (vars)
  1730.           || (! TREE_EXTERNAL (vars) && TREE_USED (vars))))
  1731.     {
  1732.       extern tree the_null_vtable_entry;
  1733.  
  1734.       /* Stuff this virtual function table's size into
  1735.      `pfn' slot of `the_null_vtable_entry'.  */
  1736.       tree nelts = array_type_nelts (TREE_TYPE (vars));
  1737.       tree *ppfn = &FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry);
  1738.       *ppfn = nelts;
  1739.       assert (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))))) == nelts);
  1740.       /* Write it out.  */
  1741.       write_vtable_entries (vars);
  1742.       if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
  1743.     store_init_value (vars, DECL_INITIAL (vars));
  1744.       rest_of_decl_compilation (vars, 0, 1, 1);
  1745.     }
  1746.   /* We know that PREV must be non-zero here.  */
  1747.   TREE_CHAIN (prev) = TREE_CHAIN (vars);
  1748. }
  1749.  
  1750. void
  1751. walk_vtables (typedecl_fn, vardecl_fn)
  1752.      register void (*typedecl_fn)();
  1753.      register void (*vardecl_fn)();
  1754. {
  1755.   tree prev, vars;
  1756.  
  1757.   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
  1758.     {
  1759.       if (TREE_CODE (vars) == TYPE_DECL
  1760.       && TYPE_LANG_SPECIFIC (TREE_TYPE (vars))
  1761.       && CLASSTYPE_VSIZE (TREE_TYPE (vars)))
  1762.     {
  1763.       if (typedecl_fn) (*typedecl_fn) (prev, vars);
  1764.     }
  1765.       else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
  1766.     {
  1767.       if (vardecl_fn) (*vardecl_fn) (prev, vars);
  1768.     }
  1769.       else
  1770.     prev = vars;
  1771.     }
  1772. }
  1773.  
  1774. extern int parse_time, varconst_time;
  1775.  
  1776. #define TIMEVAR(VAR, BODY)    \
  1777. do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
  1778.  
  1779. /* This routine is called from the last rule in yyparse ().
  1780.    Its job is to create all the code needed to initialize and
  1781.    destroy the global aggregates.  We do the destruction
  1782.    first, since that way we only need to reverse the decls once.  */
  1783.  
  1784. void
  1785. finish_file ()
  1786. {
  1787.   extern struct rtx_def *const0_rtx;
  1788.   extern int lineno;
  1789.   extern struct _iob *asm_out_file;
  1790.   int start_time, this_time;
  1791.   char *init_function_name;
  1792.  
  1793.   char *buf;
  1794.   char *p;
  1795.   tree fnname;
  1796.   tree vars = static_aggregates;
  1797.   int needs_cleaning = 0, needs_messing_up = 0;
  1798.  
  1799.   if (main_input_filename == 0)
  1800.     main_input_filename = input_filename;
  1801.   if (!first_global_object_name)
  1802.     first_global_object_name = main_input_filename;
  1803.  
  1804.   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT)
  1805.              + strlen (first_global_object_name));
  1806.  
  1807. #ifndef MERGED
  1808.   if (flag_detailed_statistics)
  1809.     dump_tree_statistics ();
  1810. #endif
  1811.  
  1812.   /* Bad parse errors.  Just forget about it.  */
  1813.   if (! global_bindings_p ())
  1814.     return;
  1815.  
  1816. #ifndef MERGED
  1817.   /* This is the first run of an unexec'd program, so save this till 
  1818.      we come back again. -- bryan@kewill.uucp */
  1819.   {
  1820.     extern int just_done_unexec;
  1821.     if (just_done_unexec)
  1822.       return;
  1823.   }
  1824. #endif
  1825.  
  1826.   start_time = gettime ();
  1827.  
  1828.   /* Push into C language context, because that's all
  1829.      we'll need here.  */
  1830.   push_lang_context (lang_name_c);
  1831.  
  1832.   /* Set up the name of the file-level functions we may need.  */
  1833.   /* Use a global object (which is already required to be unique over
  1834.      the program) rather than the file name (which imposes extra
  1835.      constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */
  1836.   sprintf (buf, FILE_FUNCTION_FORMAT, first_global_object_name);
  1837.  
  1838.   /* Don't need to pull wierd characters out of global names.  */
  1839.   if (first_global_object_name == main_input_filename)
  1840.     {
  1841.       for (p = buf+11; *p; p++)
  1842.     if (! ((*p >= '0' && *p <= '9')
  1843. #if 0                /* we want labels, which are proper C code */
  1844. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  1845.            || *p == '.'
  1846. #endif
  1847. #endif
  1848. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  1849.            || *p == '$'
  1850. #endif
  1851.            || (*p >= 'A' && *p <= 'Z')
  1852.            || (*p >= 'a' && *p <= 'z')))
  1853.       *p = '_';
  1854.     }
  1855.  
  1856.   /* See if we really need the hassle.  */
  1857.   while (vars && needs_cleaning == 0)
  1858.     {
  1859.       tree decl = TREE_VALUE (vars);
  1860.       tree type = TREE_TYPE (decl);
  1861.       if (TYPE_NEEDS_DESTRUCTOR (type))
  1862.     {
  1863.       needs_cleaning = 1;
  1864.       needs_messing_up = 1;
  1865.       break;
  1866.     }
  1867.       else
  1868.     needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
  1869.       vars = TREE_CHAIN (vars);
  1870.     }
  1871.   if (needs_cleaning == 0)
  1872.     goto mess_up;
  1873.  
  1874.   /* Otherwise, GDB can get confused, because in only knows
  1875.      about source for LINENO-1 lines.  */
  1876.   lineno -= 1;
  1877.  
  1878. #if defined(sun)
  1879.   /* Point Sun linker at this function.  */
  1880.   fprintf (asm_out_file, ".stabs \"_fini\",10,0,0,0\n.stabs \"");
  1881.   assemble_name (asm_out_file, buf);
  1882.   fprintf (asm_out_file, "\",4,0,0,0\n");
  1883. #endif
  1884.  
  1885.   fnname = get_identifier (buf);
  1886.   start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
  1887.   DECL_PRINT_NAME (current_function_decl) = "file cleanup";
  1888.   fnname = DECL_NAME (current_function_decl);
  1889.   store_parm_decls ();
  1890.  
  1891.   pushlevel (0);
  1892.   clear_last_expr ();
  1893.   push_momentary ();
  1894.   expand_start_bindings (0);
  1895.  
  1896.   /* These must be done in backward order to destroy,
  1897.      in which they happen to be!  */
  1898.   while (vars)
  1899.     {
  1900.       tree decl = TREE_VALUE (vars);
  1901.       tree type = TREE_TYPE (decl);
  1902.       tree temp = TREE_PURPOSE (vars);
  1903.  
  1904.       if (TYPE_NEEDS_DESTRUCTOR (type))
  1905.     {
  1906.       if (TREE_STATIC (vars))
  1907.         expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node), 0);
  1908.       if (TREE_CODE (type) == ARRAY_TYPE)
  1909.         temp = decl;
  1910.       else
  1911.         {
  1912.           mark_addressable (decl);
  1913.           temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
  1914.         }
  1915.       temp = build_delete (TREE_TYPE (temp), temp, integer_two_node, LOOKUP_NORMAL, 0);
  1916.       expand_expr_stmt (temp);
  1917.  
  1918.       if (TREE_STATIC (vars))
  1919.         expand_end_cond ();
  1920.     }
  1921.       vars = TREE_CHAIN (vars);
  1922.     }
  1923.  
  1924.   expand_end_bindings (getdecls (), 1, 0);
  1925.   poplevel (1, 0, 1);
  1926.   pop_momentary ();
  1927.  
  1928.   finish_function (lineno, 0);
  1929.  
  1930. #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER) && !defined(SDB_DEBUGGING_INFO)
  1931.   /* Now tell GNU LD that this is part of the static destructor set.  */
  1932.   {
  1933.     extern struct _iob *asm_out_file;
  1934.     fprintf (asm_out_file, ".stabs \"___DTOR_LIST__\",22,0,0,");
  1935.     assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
  1936.     fputc ('\n', asm_out_file);
  1937.   }
  1938. #endif
  1939.  
  1940.   /* if it needed cleaning, then it will need messing up: drop through  */
  1941.  
  1942.  mess_up:
  1943.   /* Must do this while we think we are at the top level.  */
  1944.   vars = nreverse (static_aggregates);
  1945.   if (vars != NULL_TREE)
  1946.     {
  1947.       buf[FILE_FUNCTION_PREFIX_LEN] = 'I';
  1948.  
  1949. #if defined(sun)
  1950.       /* Point Sun linker at this function.  */
  1951.       fprintf (asm_out_file, ".stabs \"_init\",10,0,0,0\n.stabs \"");
  1952.       assemble_name (asm_out_file, buf);
  1953.       fprintf (asm_out_file, "\",4,0,0,0\n");
  1954. #endif
  1955.  
  1956.       fnname = get_identifier (buf);
  1957.       start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
  1958.       DECL_PRINT_NAME (current_function_decl) = "file initialization";
  1959.       fnname = DECL_NAME (current_function_decl);
  1960.       store_parm_decls ();
  1961.  
  1962.       pushlevel (0);
  1963.       clear_last_expr ();
  1964.       push_momentary ();
  1965.       expand_start_bindings (0);
  1966.  
  1967. #ifdef SOS
  1968.       if (flag_all_virtual == 2)
  1969.     {
  1970.       tree decl;
  1971.       char c = buf[FILE_FUNCTION_PREFIX_LEN];
  1972.       buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
  1973.  
  1974.       decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier (buf), default_function_type));
  1975.       finish_decl (decl, NULL_TREE, NULL_TREE);
  1976.       expand_expr_stmt (build_function_call (decl, NULL_TREE));
  1977.       buf[FILE_FUNCTION_PREFIX_LEN] = c;
  1978.     }
  1979. #endif
  1980.  
  1981.       while (vars)
  1982.     {
  1983.       tree decl = TREE_VALUE (vars);
  1984.       tree init = TREE_PURPOSE (vars);
  1985.  
  1986.       /* If this was a static attribute within some function's scope,
  1987.          then don't initialize it here.  Also, don't bother
  1988.          with initializers that contain errors.  */
  1989.       if (TREE_STATIC (vars)
  1990.           || (init && TREE_CODE (init) == TREE_LIST
  1991.           && value_member (error_mark_node, init)))
  1992.         {
  1993.           vars = TREE_CHAIN (vars);
  1994.           continue;
  1995.         }
  1996.  
  1997.       if (TREE_CODE (decl) == VAR_DECL)
  1998.         {
  1999.           /* Set these global variables so that GDB at least puts
  2000.          us near the declaration which required the initialization.  */
  2001.           input_filename = DECL_SOURCE_FILE (decl);
  2002.           lineno = DECL_SOURCE_LINE (decl);
  2003.           emit_note (input_filename, lineno);
  2004.  
  2005.           if (init)
  2006.         {
  2007.           if (TREE_CODE (init) == VAR_DECL)
  2008.             {
  2009.               /* This behavior results when there are
  2010.              multiple declarations of an aggregate,
  2011.              the last of which defines it.  */
  2012.               if (DECL_RTL (init) == DECL_RTL (decl))
  2013.             {
  2014.               if (! (DECL_INITIAL (decl) == error_mark_node
  2015.                  || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
  2016.                      && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE)))
  2017.                 abort ();
  2018.  
  2019.               init = DECL_INITIAL (init);
  2020.               if (TREE_CODE (init) == CONSTRUCTOR
  2021.                   && CONSTRUCTOR_ELTS (init) == NULL_TREE)
  2022.                 init = NULL_TREE;
  2023.             }
  2024. #if 0
  2025.               else if (TREE_TYPE (decl) == TREE_TYPE (init))
  2026.             {
  2027. #if 1
  2028.               assert (0);
  2029. #else
  2030.               /* point to real decl's rtl anyway.  */
  2031.               DECL_RTL (init) = DECL_RTL (decl);
  2032.               assert (DECL_INITIAL (decl) == error_mark_node);
  2033.               init = DECL_INITIAL (init);
  2034. #endif                /* 1 */
  2035.             }
  2036. #endif                /* 0 */
  2037.             }
  2038.         }
  2039.           if (IS_AGGR_TYPE (TREE_TYPE (decl))
  2040.           || init == 0
  2041.           || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
  2042.         expand_aggr_init (decl, init, 0);
  2043.           else if (TREE_CODE (init) == TREE_VEC)
  2044.         expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
  2045.                           TREE_VEC_ELT (init, 1),
  2046.                           TREE_VEC_ELT (init, 2), 0),
  2047.                  const0_rtx, VOIDmode, 0);
  2048.           else
  2049.         expand_assignment (decl, init, 0, 0);
  2050.         }
  2051.       else if (TREE_CODE (decl) == SAVE_EXPR)
  2052.         {
  2053.           if (! PARM_DECL_EXPR (decl))
  2054.         {
  2055.           /* a `new' expression at top level.  */
  2056.           expand_expr (decl, const0_rtx, VOIDmode, 0);
  2057.           expand_aggr_init (build_indirect_ref (decl, 0), init, 0);
  2058.         }
  2059.         }
  2060.       else if (decl == error_mark_node)
  2061.         ;
  2062.       else abort ();
  2063.       vars = TREE_CHAIN (vars);
  2064.     }
  2065.  
  2066.       expand_end_bindings (getdecls (), 1, 0);
  2067.       poplevel (1, 0, 1);
  2068.       pop_momentary ();
  2069.  
  2070.       finish_function (lineno, 0);
  2071. #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER) && !defined(SDB_DEBUGGING_INFO)
  2072.       /* Now tell GNU LD that this is part of the static constructor set.  */
  2073.       {
  2074.     extern struct _iob *asm_out_file;
  2075.     fprintf (asm_out_file, ".stabs \"___CTOR_LIST__\",22,0,0,");
  2076.     assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
  2077.     fputc ('\n', asm_out_file);
  2078.       }
  2079. #endif
  2080.     }
  2081.  
  2082. #ifdef SOS
  2083.   if (flag_all_virtual == 2)
  2084.     {
  2085.       tree __sosDynError = default_conversion (lookup_name (get_identifier ("sosDynError")));
  2086.  
  2087.       tree null_string = build1 (ADDR_EXPR, string_type_node, combine_strings (build_string (0, "")));
  2088.       tree tags = gettags ();
  2089.       tree decls = getdecls ();
  2090.       tree entry;
  2091.       int i;
  2092.  
  2093.       entry = NULL_TREE;
  2094.       for (i = 0; i < 3; i++)
  2095.     entry = tree_cons (NULL_TREE, integer_zero_node, entry);
  2096.       zlink = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zlink_type, NULL_TREE, entry));
  2097.       TREE_LITERAL (TREE_VALUE (zlink)) = 1;
  2098.       TREE_STATIC (TREE_VALUE (zlink)) = 1;
  2099.  
  2100.       entry = NULL_TREE;
  2101.       for (i = 0; i < 5; i++)
  2102.     entry = tree_cons (NULL_TREE, integer_zero_node, entry);
  2103.       zret = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zret_type, NULL_TREE, entry));
  2104.       TREE_LITERAL (TREE_VALUE (zret)) = 1;
  2105.       TREE_STATIC (TREE_VALUE (zret)) = 1;
  2106.  
  2107.       /* Symbols with external visibility (except globally visible
  2108.      dynamic member functions) into the `zlink' table.  */
  2109.       while (decls)
  2110.     {
  2111.       if (TREE_PUBLIC (decls)
  2112.           && TREE_ASM_WRITTEN (decls)
  2113.           && (TREE_CODE (decls) != FUNCTION_DECL
  2114.           || TREE_CODE (TREE_TYPE (decls)) != METHOD_TYPE
  2115.           || TYPE_DYNAMIC (TYPE_METHOD_BASETYPE (TREE_TYPE (decls))) == 0))
  2116.         {
  2117.           entry = build (CONSTRUCTOR, zlink_type, NULL_TREE,
  2118.                  tree_cons (NULL_TREE,
  2119.                     build1 (ADDR_EXPR, string_type_node,
  2120.                         combine_strings (build_string (IDENTIFIER_LENGTH (DECL_NAME (decls)),
  2121.                                            IDENTIFIER_POINTER (DECL_NAME (decls))))),
  2122.                     tree_cons (NULL_TREE, integer_one_node,
  2123.                            build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, decls, 0)))));
  2124.           TREE_LITERAL (entry) = 1;
  2125.           TREE_STATIC (entry) = 1;
  2126.           zlink = tree_cons (NULL_TREE, entry, zlink);
  2127.         }
  2128.       decls = TREE_CHAIN (decls);
  2129.     }
  2130.  
  2131.       buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
  2132.   
  2133.       fnname = get_identifier (buf);
  2134.       start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
  2135.       fnname = DECL_NAME (current_function_decl);
  2136.       store_parm_decls ();
  2137.  
  2138.       pushlevel (0);
  2139.       clear_last_expr ();
  2140.       push_momentary ();
  2141.       expand_start_bindings (0);
  2142.  
  2143.       {
  2144.     tree decl, type;
  2145.     /* Lay out a table static to this function
  2146.        with information about all text and data that
  2147.        this file provides.  */
  2148.     tree zlink_table = finish_table (get_identifier ("__ZLINK_tbl"), zlink_type, zlink, 0);
  2149.     decl = pushdecl (build_decl (VAR_DECL, get_identifier ("_ZLINK_once"), integer_type_node));
  2150.     TREE_STATIC (decl) = 1;
  2151.     finish_decl (decl, NULL_TREE, NULL_TREE);
  2152.     expand_start_cond (truthvalue_conversion (decl), 0);
  2153.     expand_null_return ();
  2154.     expand_end_cond ();
  2155.     finish_stmt ();
  2156.     expand_expr_stmt (build_modify_expr (decl, NOP_EXPR, integer_one_node));
  2157.     type = build_function_type (void_type_node, NULL_TREE);
  2158.     decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier ("_Ztable_from_cfront"), type));
  2159.     TREE_EXTERNAL (decl) = 1;
  2160.     finish_decl (decl, NULL_TREE, NULL_TREE);
  2161.     expand_expr_stmt (build_function_call (decl, build_tree_list (NULL_TREE, zlink_table)));
  2162.     expand_null_return ();
  2163.       }
  2164.       expand_end_bindings (0, 1, 0);
  2165.       poplevel (1, 0, 1);
  2166.       pop_momentary ();
  2167.       finish_function (lineno, 0);
  2168.  
  2169.       buf[FILE_FUNCTION_PREFIX_LEN] = 'Y';
  2170.       fnname = get_identifier (buf);
  2171.       start_function (build_tree_list (NULL_TREE, get_identifier ("int")),
  2172.               build_parse_node (INDIRECT_REF, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE)), 0, 0);
  2173.       fnname = DECL_NAME (current_function_decl);
  2174.       store_parm_decls ();
  2175.  
  2176.       pushlevel (0);
  2177.       clear_last_expr ();
  2178.       push_momentary ();
  2179.       expand_start_bindings (0);
  2180.  
  2181.       {
  2182. #define SOS_VERSION 2
  2183.     tree sosVersionNumber = build_int_2 (SOS_VERSION, 0);
  2184.     tree zret_table;
  2185.  
  2186.     /* For each type defined, if is a dynamic type, write out
  2187.        an entry linking its member functions with their names.  */
  2188.  
  2189.     while (tags)
  2190.       {
  2191.         tree type = TREE_VALUE (tags);
  2192.         if (TYPE_DYNAMIC (type))
  2193.           {
  2194.         /* SOS currently only implements single inheritance,
  2195.            so we just pick up one string, if this class
  2196.            has a base class.  */
  2197.         tree base_name = CLASSTYPE_N_BASECLASSES (type) > 0 && TYPE_DYNAMIC (CLASSTYPE_BASECLASS (type, 1))
  2198.           ? build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (CLASSTYPE_BASECLASS (type, 1)))
  2199.             : null_string;
  2200.         tree dyn_table, dyn_entry = NULL_TREE, fns = CLASS_ASSOC_VIRTUALS (type);
  2201.         while (fns)
  2202.           {
  2203.             if (TREE_ASM_WRITTEN (TREE_OPERAND (TREE_VALUE (fns), 0)))
  2204.               dyn_entry = tree_cons (NULL_TREE, TREE_VALUE (fns), dyn_entry);
  2205.             else
  2206.               dyn_entry = tree_cons (NULL_TREE, __sosDynError, dyn_entry);
  2207.             fns = TREE_CHAIN (fns);
  2208.           }
  2209.         dyn_entry = nreverse (dyn_entry);
  2210.         dyn_entry = tree_cons (NULL_TREE, build1 (NOP_EXPR, TYPE_POINTER_TO (default_function_type), sosVersionNumber),
  2211.                        tree_cons (NULL_TREE, integer_zero_node,
  2212.                           tree_cons (NULL_TREE, integer_zero_node,
  2213.                                  dyn_entry)));
  2214.         dyn_table = finish_table (DECL_NAME (TYPE_NAME (type)), TYPE_POINTER_TO (default_function_type), dyn_entry, 0);
  2215.         entry = build (CONSTRUCTOR, zret_type, NULL_TREE,
  2216.                    tree_cons (NULL_TREE, build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (type)),
  2217.                       tree_cons (NULL_TREE, default_conversion (dyn_table),
  2218.                              tree_cons (NULL_TREE, build_int_2 (CLASSTYPE_VSIZE (type), 0),
  2219.                                 tree_cons (NULL_TREE, base_name,
  2220.                                        build_tree_list (NULL_TREE, integer_zero_node))))));
  2221.         TREE_LITERAL (entry) = 1;
  2222.         TREE_STATIC (entry) = 1;
  2223.         zret = tree_cons (NULL_TREE, entry, zret);
  2224.           }
  2225.         tags = TREE_CHAIN (tags);
  2226.       }
  2227.     zret_table = finish_table (get_identifier ("__Zret"), zret_type, zret, 0);
  2228.     c_expand_return (convert (build_pointer_type (integer_type_node), default_conversion (zret_table)));
  2229.       }
  2230.       expand_end_bindings (0, 1, 0);
  2231.       poplevel (1, 0, 1);
  2232.       pop_momentary ();
  2233.       finish_function (lineno, 0);
  2234.  
  2235. #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER)
  2236.       {
  2237.     extern struct _iob *asm_out_file;
  2238.     fprintf (asm_out_file, ".stabs \"___ZTOR_LIST__\",22,0,0,");
  2239.     assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
  2240.     fputc ('\n', asm_out_file);
  2241.       }
  2242. #endif
  2243.     }
  2244. #endif
  2245.  
  2246.   /* Done with C language context needs.  */
  2247.   pop_lang_context ();
  2248.  
  2249.   /* Now write out any static class variables (which may have since
  2250.      learned how to be initialized).  */
  2251.   while (pending_statics)
  2252.     {
  2253.       tree decl = TREE_VALUE (pending_statics);
  2254.       if (TREE_USED (decl) == 1
  2255.       || TREE_READONLY (decl) == 0
  2256.       || DECL_INITIAL (decl) == 0)
  2257.     rest_of_decl_compilation (decl, DECL_ASSEMBLER_NAME (decl), 1, 1);
  2258.       pending_statics = TREE_CHAIN (pending_statics);
  2259.     }
  2260.  
  2261.   this_time = gettime ();
  2262.   parse_time -= this_time - start_time;
  2263.   varconst_time += this_time - start_time;
  2264.  
  2265.   /* Now write out inline functions which had their addresses taken
  2266.      and which were not declared virtual and which were not declared
  2267.      `extern inline'.  */
  2268.   while (pending_addressable_inlines)
  2269.     {
  2270.       tree decl = TREE_VALUE (pending_addressable_inlines);
  2271.       if (! TREE_ASM_WRITTEN (decl)
  2272.       && ! TREE_EXTERNAL (decl)
  2273.       && DECL_SAVED_INSNS (decl))
  2274.     output_inline_function (decl);
  2275.       pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines);
  2276.     }
  2277.  
  2278.   start_time = gettime ();
  2279.  
  2280.   /* Now delete from the chain of variables all virtual function tables.
  2281.      We output them all ourselves, because each will be treated specially.  */
  2282.  
  2283.   /* Make last thing in global scope not be a virtual function table.  */
  2284.   vars = build_decl (VAR_DECL, get_identifier (" @%$#@!"), integer_type_node);
  2285.   TREE_EXTERNAL (vars) = 1;
  2286.   pushdecl (vars);
  2287.   /* Make this dummy variable look used.  */
  2288.   TREE_ASM_WRITTEN (vars) = 1;
  2289.   DECL_INITIAL (vars) = error_mark_node;
  2290.  
  2291.   walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl);
  2292.  
  2293.   if (write_virtuals == 2)
  2294.     {
  2295.       /* Now complain about an virtual function tables promised
  2296.      but not delivered.  */
  2297.       while (pending_vtables)
  2298.     {
  2299.       if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
  2300.         error ("virtual function table for `%s' not defined",
  2301.            IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
  2302.       pending_vtables = TREE_CHAIN (pending_vtables);
  2303.     }
  2304.     }
  2305.  
  2306.   permanent_allocation ();
  2307.   this_time = gettime ();
  2308.   parse_time -= this_time - start_time;
  2309.   varconst_time += this_time - start_time;
  2310.  
  2311.   if (flag_detailed_statistics)
  2312.     dump_time_statistics ();
  2313. }
  2314.